package com.zx.znav.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 挚爱之夕
 * @version 1.0
 * @implSpec 用户登录拦截器
 * @since 2023-06-21 15:19
 */
@Configuration
public class UserWebConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    //配置拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //前台
        //刷新token
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate))
                .addPathPatterns("/**").order(0);

        //登录拦截
        registry.addInterceptor(new UserLoginInterceptor())
                .addPathPatterns("/user/updateInfo")
                .addPathPatterns("/user/changePassword")
                .order(1);

        //后台
        registry.addInterceptor(new AdminLoginInterceptor())
                .addPathPatterns("/admin/**")
                .excludePathPatterns("/admin")
                .excludePathPatterns("/admin/login").order(1);
    }
}